<template>
    <div class="tab-bar-item" @click="handleTarget">
        <div v-if="!isActive"><slot name="icon" /></div>
        <div v-else><slot name="icon-active" /></div>
        <div :style="titleColor"><slot name="title" /></div>
    </div>
</template>

<script>
    export default {
        name: "TabBarItem",
        props: {
            link: String,
            activeColor: {
              type: String,
                default: 'blue'
            }
        },
        computed: {
            isActive(){
                return this.link.indexOf(this.$route.path) !== -1
            },
            titleColor(){
                return this.isActive?{color: this.activeColor}: {}
            }
        },
        methods: {
            handleTarget(){
                this.$router.replace(this.link)
            }
        }
    }
</script>

<style scoped>
    .tab-bar-item{
        flex: 1;
        text-align: center;
        font-size: 14px;
        color: #a6a6a6;
    }
    .tab-bar-item img{
        vertical-align: middle;
        margin-top: 2px;
    }
</style>
